<template>
  <view><web-view :webview-styles="webviewStyles" :src="url"></web-view> </view>
</template>

<script>
export default {
  data() {
    return {
      url: "",
      webviewStyles: {
        progress: {
          color: "#198fff",
        },
      },
    };
  },
  onLoad(options) {
    if (options.url) {
      this.url = options.url;
    }
  },
  onNavigationBarButtonTap(v) {
    let url = this.url;
    if (url.startsWith("http://")) {
      url = url.substring(7, url.length);
    } else if (url.startsWith("https://")) {
      url = url.substring(8, url.length);
    }
    if (url.indexOf("/") >= 0) {
      url = url.substring(0, url.indexOf("/"));
    }
    // #ifdef APP-PLUS
    uni.showActionSheet({
      title: "此网页由 " + url + " 提供",
      itemList: ["分享", "复制链接", "刷新", "浏览器打开"],
      success: (res) => {
        let index = res.tapIndex;
        if (index == 0) {
          uni.shareWithSystem({
            href: this.url,
          });
        } else if (index == 1) {
          uni.setClipboardData({
            data: this.url,
            success: () => {
              this.msg("复制成功");
            },
          });
        } else if (index == 2) {
          let currentWebview = this.$scope.$getAppWebview();
          let wv = currentWebview.children()[0];
          wv.reload();
        } else if (index == 3) {
          plus.runtime.openURL(this.url);
        }
      },
    });
    // #endif
    // #ifndef APP-PLUS
    uni.showActionSheet({
      title: "此网页由 " + url + " 提供",
      itemList: ["复制链接"],
      success: (res) => {
        let index = res.tapIndex;
        if (index == 0) {
          uni.setClipboardData({
            data: this.url,
            success: () => {
              this.msg("复制成功");
            },
          });
        }
      },
    });
    // #endif
  },
  methods: {},
};
</script>

<style lang="scss" scoped>
</style>
